//
//  DHOrderTimeViewController.m
//  DHKuaiYi
//
//  Created by  chenhanmao on 2016/11/16.
//  Copyright © 2016年 30-陈辉华. All rights reserved.
//

#import "DHOrderTimeViewController.h"
#import <Masonry.h>
#import <SobotKit/SobotKit.h>
#import "DHAppointmentViewController.h"

static NSString *dateCellID = @"dateCellID";
@interface DHOrderTimeViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

/**  预约时间表  */
@property(nonatomic,weak) UICollectionView *collectionView;

@end

@implementation DHOrderTimeViewController

#pragma mark - UICollectionViewDataSource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 4;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 8;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:dateCellID forIndexPath:indexPath];
    cell.backgroundColor = [UIColor XHH_randomColor];
    return cell;
    
}


#pragma mark - 界面布局
- (void)xhhSetupSubviews {
    
    //医生预约时间
//    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
//    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame: CGRectZero collectionViewLayout:flowLayout];
//    self.collectionView = collectionView;
//    collectionView.dataSource = self;
//    collectionView.delegate = self;
//    
//    [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:dateCellID];
//    
//    [self.view addSubview: collectionView];
//    
//    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.right.equalTo(self.view);
//        make.top.equalTo(self.view).offset(50);
//        make.height.mas_equalTo(300);
//    }];
//    UIView *orderTimeView = [[UIView alloc] init];
//    [self.view addSubview:orderTimeView];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"datetime1"]];
    [self.view addSubview:imageView];
    
    imageView.center = self.view.center;
    CGFloat height = imageView.frame.size.height /  (imageView.frame.size.width / self.view.frame.size.width);
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view).offset(80);
        make.height.mas_equalTo(height);
    }];
    
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:@"有号" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor globalColor] forState:UIControlStateNormal];
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(makeAnAppointment) forControlEvents:UIControlEventTouchUpInside];
    
    CGFloat width = self.view.frame.size.width / 8;
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(width, width));
        make.left.mas_equalTo(self.view).offset(width - 1);
        make.top.equalTo(self.view).offset(80 + width);
    }];
    
    UIButton *btn1 = [[UIButton alloc] init];
    [btn1 setTitle:@"有号" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor globalColor] forState:UIControlStateNormal];
    [self.view addSubview:btn1];
    [btn1 addTarget:self action:@selector(makeAnAppointment) forControlEvents:UIControlEventTouchUpInside];
    
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(width, width));
        make.left.mas_equalTo(self.view).offset(width * 4 + 1);
        make.top.equalTo(self.view).offset(80 + width * 2);
    }];
    
    UIButton *btn2 = [[UIButton alloc] init];
    [btn2 setTitle:@"有号" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor globalColor] forState:UIControlStateNormal];
    [self.view addSubview:btn2];
    [btn2 addTarget:self action:@selector(makeAnAppointment) forControlEvents:UIControlEventTouchUpInside];
    
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(width, width));
        make.left.mas_equalTo(self.view).offset(width * 5 + 2);
        make.top.equalTo(self.view).offset(80 + width * 3);
    }];
    
    //咨询医生按钮
    UIButton *askBtn = [[UIButton alloc] init];
    [self.view addSubview:askBtn];
    [askBtn setTitle:@"咨询医生" forState:UIControlStateNormal];
    [askBtn setBackgroundColor:[UIColor globalColor]];
    [askBtn addTarget:self action:@selector(askToDoctor) forControlEvents:UIControlEventTouchUpInside];
    
    //自动布局
    [askBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.view).offset(8);
        make.bottom.right.mas_equalTo(self.view).offset(-8);
        make.height.mas_equalTo(44);
    }];
}

#pragma mark - 预约
- (void)makeAnAppointment {
    
    DHAppointmentViewController *VC = [[DHAppointmentViewController alloc] init];
    
    [self.navigationController pushViewController:VC animated:YES];
    
    
}

#pragma mark - 聊天
- (void) askToDoctor {
    [self createRobot];
}

- (void)createRobot {
    //企业编号，必填
    
    NSString *sysNumber=@"c05b888a771c4c4fb9f2bb93f8a42245";
    
    //启动
    
    ZCLibInitInfo *initInfo = [ZCLibInitInfo new];
    
    initInfo.enterpriseId = sysNumber;
    
    //用户id，用于标识用户，建议填写
    
    initInfo.userId=@"Your userId";
    
    initInfo.phone=@"Your phone";
    
    initInfo.nickName=@"Your nickName";
    
    initInfo.email=@"Your user email";
    
    ZCKitInfo *uiInfo=[ZCKitInfo new];
    
    uiInfo.info=initInfo;
    
    [self customerUI:uiInfo];
    
    [ZCSobot startZCChatView:uiInfo with:self
     
                   pageBlock:^(ZCUIChatController *object, ZCPageBlockType type) {
                       
                       //点击返回
                       
                       if(type==ZCPageBlockGoBack){
                           
                           NSLog(@"点击了关闭按钮");
                           
                       }
                       
                       //页面UI初始化完成，可以获取UIView，自定义UI
                       
                       if(type==ZCPageBlockLoadFinish){
                           
                           //banner 返回按钮
                           
                           [object.backButton setTitle:@" 返回" forState:UIControlStateNormal];
                           
                           //banner 标题
                           
                           [object.titleLabel setFont:[UIFont systemFontOfSize:20]];
                           
                           //banner 底部View
                           
                           //[object.topView setBackgroundColor:[UIColor greenColor]];
                           
                           //输入框
                           
                           //UITextView *tv=[object getChatTextView];
                           
                           //[tv setBackgroundColor:[UIColor redColor]];
                           
                       }
                       
                       //messageLinkClick ,不重写，系统自己跳转，sdk内部不做任何处理
                       
                   } messageLinkClick:nil];

}

- (void)customerUI:(ZCKitInfo *) kitInfo{
    
    /**
     
     * 自定义信息
     
     */
    
    //顶部导航条标题文字 评价标题文字 系统相册标题文字 评价客服（立即结束 取消）按钮文字
    
    kitInfo.titleFont = [UIFont systemFontOfSize:18];
    
    //返回按钮 输入框文字 评价客服是否有以下情况 label 文字 提价评价按钮
    
    kitInfo.listTitleFont = [UIFont systemFontOfSize:18];
    
    //没有网络提醒的button 没有更多记录label的文字 语音输入的按钮文字 评价不满意（4个button）文字
    
    //占位图片的lablel文字 语音输入时间label文字 语音tipLabel的文字 voiceButton标题文字
    
    kitInfo.listDetailFont = [UIFont systemFontOfSize:18];
    
    //消息提醒 （转人工、客服接待等）
    
    kitInfo.listTimeFont = [UIFont systemFontOfSize:18];
    
    //聊天气泡中的文字
    
    kitInfo.chatFont = [UIFont systemFontOfSize:18];
    
    //聊天的背景颜色
    
    kitInfo.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.00];
    
    //导航、客服气泡、线条的颜色
    
    kitInfo.customBannerColor = [UIColor colorWithRed:0.82 green:0.91 blue:0.99 alpha:1.00];
    
    //左边气泡的颜色
    
    kitInfo.leftChatColor = [UIColor colorWithRed:1.00 green:1.00 blue:1.00 alpha:1.00];
    
    //右边气泡的颜色
    
    kitInfo.rightChatColor = [UIColor colorWithRed:0.64 green:0.90 blue:0.39 alpha:1.00];
    
    //底部bottom的背景颜色
    
    kitInfo.backgroundBottomColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.00];
    
    //底部bottom的输入框线条背景颜色
    
    //    kitInfo.backgroundBottomLineColor = [UIColor redColor];
    
    //提示气泡的背景颜色
    
    kitInfo.BgTipAirBubblesColor = [UIColor redColor];
    
    //顶部文字的颜色
    
    kitInfo.topViewTextColor = [UIColor blackColor];
    
    //提示气泡文字颜色
    
    kitInfo.tipLayerTextColor = [UIColor colorWithRed:0.81 green:0.81 blue:0.81 alpha:1.00];
    
    //左边气泡文字的颜色
    
    kitInfo.leftChatTextColor = [UIColor colorWithRed:0.02 green:0.02 blue:0.02 alpha:1.00];
    
    //右边气泡文字的颜色[注意：语音动画图片，需要单独替换]
    
    kitInfo.rightChatTextColor = [UIColor colorWithRed:0.02 green:0.02 blue:0.02 alpha:1.00];
    
    //时间文字的颜色
    
    kitInfo.timeTextColor = [UIColor colorWithRed:0.93 green:0.93 blue:0.93 alpha:1.00];
    
    //客服昵称颜色
    
    kitInfo.serviceNameTextColor = [UIColor blackColor];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
